package com.guigu.ssyx.sys.controller;


import com.atguigu.ssyx.model.sys.RegionWare;
import com.atguigu.ssyx.vo.sys.RegionWareQueryVo;
import com.baomidou.mybatisplus.core.metadata.IPage;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.guigu.ssyx.common.result.Result;

import com.guigu.ssyx.sys.service.RegionWareService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(value = "区域代理管理")
@RestController
@RequestMapping("/admin/sys/regionWare")
@CrossOrigin
@SuppressWarnings({"unchecked", "rawtypes"})
public class RegionWareController {

    @Autowired
    private RegionWareService regionWareService;


    @GetMapping("{page}/{limit}")
    @ApiModelProperty("获取开通区域列表")
    public Result index(@PathVariable Long page, @PathVariable Long limit, RegionWareQueryVo regionWareQueryVo) {

        Page<RegionWare> regionWarePage = new Page<>(page,limit);

        IPage<RegionWare> pageModel = regionWareService.selectByPage(regionWarePage,regionWareQueryVo);

        return Result.ok(pageModel);


    }

    @PostMapping("save")
    @ApiModelProperty("添加开通区域")
    public Result save(@RequestBody RegionWare regionWare) {

        regionWareService.saveRegionWare(regionWare);
        return Result.ok(null);
    }

    @ApiOperation(value = "删除开通区域")
    @DeleteMapping("remove/{id}")
    public Result remove(@PathVariable Long id){
        regionWareService.removeById(id);
        return Result.ok(null);
    }

    @ApiOperation(value = "更新状态")
    @GetMapping("updateStatus/{id/{status}")
    public Result updateStatus(@PathVariable Long id,@PathVariable Integer status){
        regionWareService.updateStatus(id,status);
        return Result.ok(null);
    }




}
